<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/11/28
 * Time: 10:19
 */
$all_data = array(
    1 => array('学PHP，冲击月薪10000+你也可以！','......'),
    2 => array('传智播客PHP项目答辩，群雄竞技牛人辈出','......'),
    3 => array('夏“超”激情，Ajax公开课与你想约','......'),
    4 => array('学PHP编程，不做孬种程序员','......'),
);
$id = isset($_GET['id']) ? intval($_GET['id']) : 1;
//计算上一篇文章的id
$id_prev = $id-1;
//计算下一篇文章的id
$id_next = $id+1;
//防止id越界（最高为4，最低为1）
if($id <1) $id=1;
if($id >4) $id=4;
if($id_prev <1) $id_prev = 1;
if($id_next >4) $id_next = 4;
if(isset($_COOKIE['histroy'])) {
    //获取Cookie,保存到数组中，限制数组最多只能4个元素
    $cookie_arr = explode(',',$_COOKIE['histroy'],4);
    foreach ($cookie_arr as $k=>$v){
        $cookie_arr[$k] =intval($cookie_arr[$k]);
        if($v == $id) unset($cookie_arr[$k]);
    }
    if(count($cookie_arr)>3) array_shift($cookie_arr);
    $cookie_arr[] = $id;
    setcookie('histroy',implode(',',$cookie_arr));
}else{
    $cookie_arr = array($id);
    setcookie('histroy',$id);
}
$data = $all_data[$id];
$data_histroy = array();
foreach ($cookie_arr as $v){
    if(isset($all_data[$v])){
        $data_histroy[$v] = $all_data[$v][0];
    }
}
if(isset($_GET['action'])){
    if($_GET['action'] == 'clear'){
        $cookie_arr = array();
        setcookie('histroy','',time()-1);
    }
}
 require ('article_html.php');
